package com.example.shop_2207.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.shop_2207.R
import com.example.shop_2207.entity.CategoryEntity
import com.example.shop_2207.net.GlideUtils

/**
 * 一级分类的适配器
 */
class OneAdapter(list: MutableList<CategoryEntity>):BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_one,list) {
    //选中item的id  默认为1 应为第一个item的id为1
    @JvmField
    var selectedId = 1
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.one_name,item.category_name)//修改文本文字
        holder.getView<LinearLayout>(R.id.one_ll).background  = if(selectedId==item.id){
            ColorDrawable(Color.RED)
        }else{null}
    }
    fun setSelectedId(id:Int){
        selectedId = id
    }
}